Poly-Alphabetic Cipher

Module 01 / Lesson 04

Visual Explanation


Evolution of Substitution

A Poly-Alphabetic cipher is a substitution cipher that uses multiple cipher alphabets to encrypt the plaintext. This was designed to defeat Frequency Analysis, because the same letter in the plaintext can be represented by different letters in the ciphertext depending on its position.


The Core Concept:

Instead of having one fixed mapping (like Mono-alphabetic), we use a set of different substitution rules. The most famous example is the Vigenère Cipher, which uses a keyword to switch between 26 different Caesar alphabets.


Python Concept Illustration

This example shows how a simple key changes the alphabet per character:

def poly_sub_demo(text, key):
    # Multiple substitution rules (Simplified)
    alphabets = [
        "QWERTYUIOPASDFGHJKLZXCVBNM", # Alphabet 1
        "MNBVCXZLKJHGFDSAPOIUYTREWQ", # Alphabet 2
        "PLMOKNIJBUHVYGCTFXRDZESWAQ"  # Alphabet 3
    ]
    result = ""
    for i, char in enumerate(text.upper()):
        if char.isalpha():
            # Cycle through the available alphabets using the key index
            current_alphabet = alphabets[i % len(alphabets)]
            idx = ord(char) - ord('A')
            result += current_alphabet[idx]
        else:
            result += char
    return result

print(poly_sub_demo("HELLO", "KEY"))